package tools;

public class SiftedQueue {
	private int head;
	private int tail;
	private String[] list;
	public SiftedQueue(int length){
		list=new String[length+1];
		head=0;
		tail=0;
	}
	private int next(int n) {
		int result=n+1;
		if(result>=list.length) {
			result=0;
		}
		return result;
	}
	synchronized public void push(String e) {
		if(next(tail)==head) {
			pop();
		}
		list[tail]=e;
		tail=next(tail);
	}
	synchronized public String pop() {
		String result=null;
		if(head!=tail) {
			result=list[head];
			head=next(head);
		}
		return result;
	}
}
